<?php


namespace models\Traits;


use Yaf\Registry;

trait SendTrait
{
    /**
     * 返回成功
     */
    public static function returnMsg($code = 200,$message = 'success',$data = [],$header = ['charset'=>'utf-8'])
    {
        http_response_code($code);    //设置返回头部
        $return['code'] = (int)$code;
        $return['message'] = $message;
        $return['data'] = is_array($data) ? $data : ['info'=>$data];
        // 发送头部信息
        header('content-type:application/json');
        foreach ($header as $name => $val) {
            if (is_null($val)) {
                header($name);
            } else {
                header($name . ':' . $val);
            }
        }
        exit(json_encode($return,JSON_UNESCAPED_UNICODE));
    }

    /**
     * 清除登陆产生的缓存
     * @return bool
     */
    public function cacheClear(){
        Registry::get('rdm')->delHash('menu:'.session_id().':rules');
        Registry::get('rdm')->delSting('menu:'.session_id().':rule');
        Registry::get('rdm')->delSting('menu:'.session_id().':menu');
        return true;
    }

    protected function _setsummernote(){
        $this->getView()->display('/public/summernote.phtml');
    }
}
